<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>数组的方法-forEach</title>
</head>
<body>
  <script>
    /*
      forEach：
        遍历数组（迭代），来简化for循环
    */
    // let strs = ['Y', 'Y', 'D', 'S']
    // strs.forEach((item, index, array) => {
    //   console.log(item, index, array)
    // })
    let nums = [10, 20, 30, 40]
    let sum = 0
    nums.forEach(item => sum += item)
    console.log(sum)

  </script>
</body>
</html>
